package cn.wolfcode.Utlis;

import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;

import java.util.Date;
import java.util.HashMap;

//jwt工具类
public class JwtUtlis {
  //定义秘钥和过期时间
    private static String miniKey = "xiaozhi";
    private static Long expireTime = 3600*1000*24L;

    //创建秘钥
    public static String createJwt(HashMap<String,Object> claims){
        return Jwts.builder()
                .setClaims(claims)
                .setExpiration(new Date(System.currentTimeMillis()+expireTime))
                .signWith(SignatureAlgorithm.HS256,miniKey)
                .compact();
    }
    public static Claims parseJwt(String jwt){
        return Jwts.parser()
                .setSigningKey(miniKey)
                .parseClaimsJws(jwt)
                .getBody();
    }
}
